import { Badge, Descriptions, Divider, Drawer } from "antd";
import { forwardRef, useImperativeHandle, useMemo, useState } from "react"
import DisplayLabel from "@/components/displayLabel";

const ViewFormModal = forwardRef((props, ref) => {
  const [fullData, setFullData] = useState({
    jobId: undefined,
    jobName: undefined,
    jobGroup: undefined,
    invokeTarget: undefined,
    cronExpression: undefined,
    misfirePolicy: '1',
    concurrent: '1',
    status: '0'
  })
  const [isModalOpen, setIsModalOpen] = useState()

  useImperativeHandle(ref, () => ({
    showModal: (data) => {
      setFullData(data)
      setIsModalOpen(true)
    },
  }));

  const handleCancel = () => {
    setIsModalOpen(false)
  };
  return <Drawer width={750} open={isModalOpen} placement="right"
    closable={false} onClose={handleCancel}>
    <Descriptions
      title="操作信息"
      layout="vertical"
      bordered
      column={3}
    >
      <Descriptions.Item label="操作模块">{fullData.title}</Descriptions.Item>
      <Descriptions.Item label="登录信息">{fullData.operName} / {fullData.operIp} / {fullData.operLocation}</Descriptions.Item>
      <Descriptions.Item label="请求方式">{fullData.requestMethod}</Descriptions.Item>
      <Descriptions.Item label="请求地址">{fullData.operUrl}</Descriptions.Item>
      <Descriptions.Item label="操作方法" span={2}>
        <div style={{ 'wordBreak': 'break-all' }}>{fullData.method}</div>
      </Descriptions.Item>
    </Descriptions>
    <Divider />
    <Descriptions
      title="接口信息"
      layout="vertical"
      bordered
      column={3}
    >
      <Descriptions.Item label="请求参数" span={3}>{fullData.operParam}</Descriptions.Item>
      <Descriptions.Item label="返回参数" span={3}>{fullData.jsonResult}</Descriptions.Item>
      <Descriptions.Item label="操作状态">
        <Badge status={fullData.status == '0' ? 'processing' : 'error'} text={<DisplayLabel value={fullData.status} type="sys_common_status" />} />
      </Descriptions.Item>
      <Descriptions.Item label="操作时间">{fullData.operTime}</Descriptions.Item>
      <Descriptions.Item label="耗时">{fullData.takeUpTime}毫秒</Descriptions.Item>
      {fullData.status == 1 && <Descriptions.Item label="异常信息">{fullData.errorMsg}毫秒</Descriptions.Item>}
    </Descriptions>
    {!!fullData.logContent && <>
      <Divider />
      <Descriptions
        title="变更记录"
        layout="vertical"
        bordered
        column={3}
      >
        <Descriptions.Item label="表单ID" span={3}>{fullData.formId}</Descriptions.Item>
        <Descriptions.Item label="变更情况" span={3}>{fullData.logContent}</Descriptions.Item>
      </Descriptions>
    </>}
  </Drawer>
})

export default ViewFormModal